<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/9/2
  Time: 18:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/common/common.jsp"%>
<html>
<head>
    <link rel="icon" href="">
    <title>Title</title>
    <script type="text/javascript">
        function login(){
            $.ajax({
                url:"<%=path%>/user/login",//请求需要访问的地址
                type:"post",//请求方式 默认为get 可以设置为post
                dataType:"json",//返回值类型 html,json,text,xml
                data: $("#loginForm").serialize(),//前台到后台的参数，没有数据时可以不写
                async : true,//true代表异步刷新，false代表同步刷新
                success : function (result){//成功回调函数
                        if(result == 1){
                         alert("该账号未注册");
                     }else if (result == 2){
                         alert("密码输入次数过多，现强制冻结！")
                     }else if (result == 3) {
                         alert("密码错误，请重新输入")
                     }else if (result == 5){
                            alert("验证码错误")
                        } else{
                            location.href="<%=path%>/bootstrap.jsp";
                     }
                },
                error : function (result){//错误回调函数
                    alert("网络异常，请刷新");
                }
            })
        }
        function change_img(){
            $("#img_id").attr("src","<%=path%>/code/vcode?time="+new Date().toLocaleDateString());
            $.get("<%=path%>/code/getCode",function (result){
                $("[name=code]").val(result);
            })
        }
        function register(){
            location.href="<%=path%>/register.jsp";
        }
    </script>
</head>
<body>
    <div class="container-fluid" align="center">
        <div class="panel panel-primary" style="width:300px;">
            <div class="panel-heading">
                <h1>登录</h1>
            </div>
            <div class="panel-body">
                <form id="loginForm">
                    <div class="form-group">
                        <label for="name">账号</label>
                        <input type="text" class="form-control" name="uname" id="name"
                               placeholder="请输入账号">
                        <div id="tips"></div>
                    </div>
                    <div class="form-group">
                        <label for="pwd">密码</label>
                        <input type="password" class="form-control" name="password" id="pwd">
                    </div>
                    <div class="form-group">
                        <label for="vcode">验证码</label>
                        <input type="text" class="form-control" name="code" id="vcode"
                               placeholder="请输入验证码">
                        <img  id="img_id"  src="<%=path%>/code/vcode" onclick="change_img()">
                    </div>
                    <input type="button" class="btn btn-success btn-lg" value="登录" onclick="login()">
                    <input type="button" class="btn btn-success btn-lg" value="注册" onclick="register()">
                </form>
            </div>
            <div class="panel-footer">
                <a href="#">忘记密码？</a>
            </div>
        </div>
    </div>

</form>
</body>
</html>
